<?php

$CONFIG_FILE="./config.csv";
$DSN='mysql:host=localhost;dbname=config';
$USER='conf';
$PASSWORD='conf';

try {
	$dbh = new PDO($DSN, $USER, $PASSWORD);
} catch (PDOException $e) {
    print "Erreur !: " . $e->getMessage() . "<br/>";
    die();
}

$i=0;
$handle = @fopen($CONFIG_FILE, "r");
if ($handle) {
    while (!feof($handle)) {
        $buffer = fgets($handle, 4096);
		$elt=explode (";", $buffer);
		$REQ="INSERT INTO CONFIGURATION VALUES (NULL, \"".$elt[0]."\", \"".$elt[1]."\", \"".$elt[2]."\",\"".$elt[3]."\",\"".$elt[4]."\",\"".$elt[5]."\", ".$elt[6].");";
		echo "* $REQ";
		$stmt=$dbh->query($REQ);
		if (!$stmt) {
			echo "\nPDO::errorInfo():\n";
			print_r($dbh->errorInfo());
		} else { 
			$i++;
		}
    }
    fclose($handle);
}
unset($dbh);
echo "*$i insertions en base.";
?>